<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta name="baidu-site-verification" content="bk1wz1wzS4">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">



<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css">


  <meta name="keywords" content="开发,">








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0">






<meta name="description" content="关于ionic报错错误类型：Application Error The connection to the server was unsucessful.(file:///android_asset/www/index.html)这个问题我研究了半天，最终被我自己折服了，原因是在index.html中请求了远程的文件，一旦请求不了，Android内置的浏览器不会像平常一样跳过，而是一直进行请求，但">
<meta name="keywords" content="开发">
<meta property="og:type" content="article">
<meta property="og:title" content="破万卷APP总结四">
<meta property="og:url" content="https://youandme66.github.io/2017/04/16/first/index.html">
<meta property="og:site_name" content="腊月的季节">
<meta property="og:description" content="关于ionic报错错误类型：Application Error The connection to the server was unsucessful.(file:///android_asset/www/index.html)这个问题我研究了半天，最终被我自己折服了，原因是在index.html中请求了远程的文件，一旦请求不了，Android内置的浏览器不会像平常一样跳过，而是一直进行请求，但">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-04-18T14:52:52.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="破万卷APP总结四">
<meta name="twitter:description" content="关于ionic报错错误类型：Application Error The connection to the server was unsucessful.(file:///android_asset/www/index.html)这个问题我研究了半天，最终被我自己折服了，原因是在index.html中请求了远程的文件，一旦请求不了，Android内置的浏览器不会像平常一样跳过，而是一直进行请求，但">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'youandme'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://youandme66.github.io/2017/04/16/first/">





  <title> 破万卷APP总结四 | 腊月的季节 </title>
  <script>
  (function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
  })();
</script>
</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">腊月的季节</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope="" itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="https://youandme66.github.io/2017/04/16/first/">

  <span style="display:none" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
    <meta itemprop="name" content="腊月的季节">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/uploads/avatar.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="腊月的季节">
    <span style="display:none" itemprop="logo" itemscope="" itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="腊月的季节" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                破万卷APP总结四
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-04-16T00:00:00+08:00">
                2017-04-16
              </time>
            

            

            
          </span>

          
            <span class="post-category">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/破万卷APP/" itemprop="url" rel="index">
                    <span itemprop="name">破万卷APP</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
            <!--noindex-->
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                  <a href="/2017/04/16/first/#comments" itemprop="discussionUrl">
                    <span class="post-comments-count hc-comment-count" data-xid="2017/04/16/first/" itemprop="commentsCount"></span>
                  </a>
                </span>
              </span>
              <!--/noindex-->
            
          

          

          
          
             <span id="/2017/04/16/first/" class="leancloud_visitors" data-flag-title="破万卷APP总结四">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">阅读次数 </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="关于ionic报错"><a href="#关于ionic报错" class="headerlink" title="关于ionic报错"></a>关于ionic报错</h3><p>错误类型：Application Error The connection to the server was unsucessful.(file:///android_asset/www/index.html)<br>这个问题我研究了半天，最终被我自己折服了，原因是在index.html中请求了远程的文件，一旦请求不了，Android内置的浏览器不会像平常一样跳过，而是一直进行请求，但Android页面启动一旦过程就会报这个错误，所以一旦出现这个错误，如果你不是一个很大型的软件，可以试着检查一下你请求的任何文件，是否都在本地。</p>
<h3 id="关于请求跨域和socket-io跨域"><a href="#关于请求跨域和socket-io跨域" class="headerlink" title="关于请求跨域和socket.io跨域"></a>关于请求跨域和socket.io跨域</h3><p>这个问题同上个问题，我是一起解决的，导致遇到这类问题的主要原因是，没有看源码。要解决这个问题，我们必须知道同域和异域，必须知道请求头和请求体，跨域是如何造成的等等这些问题，在了解了实质以后，我们有很多方法可以解决，第一是客户端，第二是服务端，我解决采用的是服务端解决。<br>解决方案:就是更改客户端的请求头，或者更改对客户端的要求。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">app.use(<span class="function"><span class="keyword">function</span>(<span class="params">req, res, next</span>) </span>&#123; </span><br><span class="line">    res.setHeader(<span class="string">'Access-Control-Allow-Origin'</span>, <span class="string">'*'</span>);  </span><br><span class="line">    res.header(<span class="string">'Access-Control-Allow-Credentials'</span>, <span class="literal">true</span>);    </span><br><span class="line">    res.header(<span class="string">'Access-Control-Allow-Methods'</span>, <span class="string">'POST, GET, PUT, DELETE, OPTIONS'</span>);</span><br><span class="line">    res.header(<span class="string">"Access-Control-Allow-Headers"</span>, <span class="string">"Origin, X-Requested-With, Content-Type, Accept"</span>);    </span><br><span class="line">     <span class="keyword">if</span> (req.method == <span class="string">'OPTIONS'</span>) &#123;</span><br><span class="line">       res.send(<span class="number">200</span>); </span><br><span class="line">     &#125;</span><br><span class="line">    <span class="keyword">else</span> &#123;</span><br><span class="line">       next();</span><br><span class="line">    &#125;   </span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></p>
<p>关于这里面的OPTIONS请求，这里我就不多说了，可以自己去了解。<br>这是express的一个中间件。</p>
<h3 id="socket-io跨域"><a href="#socket-io跨域" class="headerlink" title="socket.io跨域"></a>socket.io跨域</h3><p>这个问题是因为没有看源码，不知道传递参数的拆解。<br>服务端:<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> io = <span class="built_in">require</span>(<span class="string">"socket.io"</span>).listen(server,&#123;<span class="attr">origin</span>:<span class="string">'*:*'</span>&#125;);</span><br></pre></td></tr></table></figure></p>
<p>客户端:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> socket = io.connect(<span class="string">'http://localhost:3000'</span>,&#123;<span class="attr">rememberTransport</span>:<span class="literal">true</span>,<span class="attr">timeout</span>:<span class="number">1500</span>&#125;);</span><br></pre></td></tr></table></figure>
<p>ok，就是这样</p>
<h3 id="socket提取session"><a href="#socket提取session" class="headerlink" title="socket提取session"></a>socket提取session</h3><p>要实现socket可以提取session，首先我们要弄清session。<br>session是基于cookie实现的，在客户端存有一个session的cookie key值，这个key在不变的情况下是connect.id。所以在提取这个key值时，必须使用cookieParser()。找session肯定要知道session的存储位置，所以肯定要有sessionStore，一般有mongodb,mysql,redis等等。有了这个我们就可以实现了。<br>重要代码:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> sessionScoket = <span class="built_in">require</span>(<span class="string">'session.socket.io'</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> sessionStore = <span class="keyword">new</span> redisStore(&#123;</span><br><span class="line">  port:cookiecfg.redis_port,</span><br><span class="line">  host:cookiecfg.redis_host</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> sessionScokets = <span class="keyword">new</span> sessionScoket(io,sessionStore,cookieParser(cookiecfg.session_secret));</span><br><span class="line">sessionScokets.on(<span class="string">'connection'</span>,instantCtrl.instantMessage);</span><br></pre></td></tr></table></figure>
<p>可以发现最终的socket都是sessionSocket来实现了。</p>
<h3 id="关于ng-repeat即时更新页面滚动"><a href="#关于ng-repeat即时更新页面滚动" class="headerlink" title="关于ng-repeat即时更新页面滚动"></a>关于ng-repeat即时更新页面滚动</h3><p>\$scope.\$apply();<br>var viewScroll =  \$ionicScrollDelegate.\$getByHandle(‘messageDetailsScroll’);<br>viewScroll.scrollBottom();</p>
<p>\$scope.messagedetail.messages[\$scope.messagedetail.messages.length]={‘isFromMe’:false,’message’:\$scope.send_content};</p>
<p>\$scope.\$watch(\$scope.sum, function(newVal, oldVal) {  </p>
<pre><code>\$scope.iphone.fre = newVal &gt;= 100 ? 0 : 10;  
</code></pre><p>});<br>parseInt(“1234blue”); //returns 1234<br>parseInt(“0xA”); //returns 10<br>parseInt(“22.5”); //returns 22<br>parseInt(“blue”); //returns NaN<br>parseInt(“AF”, 16); //returns 175<br>parseInt(“10”, 2); //returns 2<br>parseInt(“10”, 8); //returns 8<br>parseInt(“10”, 10); //returns 10</p>
<p>stringObject.replace(regexp/substr,replacement)</p>
<h3 id="关于socket操作"><a href="#关于socket操作" class="headerlink" title="关于socket操作"></a>关于socket操作</h3><p>服务端<br>io.on(‘connection’,function(socket));//监听客户端连接,回调函数会传递本次连接的socket</p>
<p>io.sockets.emit(‘String’,data);//给所有客户端广播消息</p>
<p>io.sockets.socket(socketid).emit(‘String’, data);//给指定的客户端发送消息</p>
<p>socket.on(‘String’,function(data));//监听客户端发送的信息</p>
<p>socket.emit(‘String’, data);//给该socket的客户端发送消息</p>
<p>广播消息</p>
<p>//给除了自己以外的客户端广播消息<br>socket.broadcast.emit(“msg”,{data:”hello,everyone”});<br>//给所有客户端广播消息<br>io.sockets.emit(“msg”,{data:”hello,all”});<br>分组</p>
<p>socket.on(‘group1’, function (data) {<br>        socket.join(‘group1’);<br>});<br>socket.on(‘group2’,function(data){<br>        socket.join(‘group2’);<br> });<br>客户端发送</p>
<p>socket.emit(‘group1’)，就可以加入group1分组；<br>socket.emit(‘group2’)，就可以加入group2分组；</p>
<p>一个客户端可以存在多个分组（订阅模式）</p>
<p>踢出分组</p>
<p>socket.leave(data.room);</p>
<p>对分组中的用户发送信息</p>
<p>//不包括自己<br>socket.broadcast.to(‘group1’).emit(‘event_name’, data);<br>//包括自己<br>io.sockets.in(‘group1’).emit(‘event_name’, data);<br>broadcast方法允许当前socket client不在该分组内</p>
<p>获取连接的客户端socket</p>
<p>io.sockets.clients().forEach(function (socket) {<br>    //…..<br>})<br>获取分组信息</p>
<p>//获取所有房间（分组）信息<br>io.sockets.manager.rooms<br>//来获取此socketid进入的房间信息<br>io.sockets.manager.roomClients[socket.id]<br>//获取particular room中的客户端，返回所有在此房间的socket实例<br>io.sockets.clients(‘particular room’)<br>另一种分组方式</p>
<p>io.of(‘/some’).on(‘connection’, function (socket) {<br>    socket.on(‘test’, function (data) {<br>        socket.broadcast.emit(‘event_name’,{});<br>    });<br>});<br>客户端</p>
<p>var socket = io.connect(‘ws://103.31.201.154:5555/some’)<br>socket.on(‘even_name’,function(data){<br>   console.log(data);<br>})<br>客户端都链接到ws://103.31.201.154:5555 但是服务端可以通过io.of(‘/some’)将其过滤出来。</p>
<p>另外，Socket.IO提供了4个配置的API：io.configure, io.set, io.enable, io.disable。其中io.set对单项进行设置，io.enable和io.disable用于单项设置布尔型的配置。io.configure可以让你对不同的生产环境（如devlopment，test等等）配置不同的参数。</p>
<p>客户端操作<br>建立一个socket连接</p>
<p>var socket = io(“ws://103.31.201.154:5555”);</p>
<p>监听服务消息</p>
<p>socket.on(‘msg’,function(data){<br>    socket.emit(‘msg’, {rp:”fine,thank you”}); //向服务器发送消息<br>    console.log(data);<br>});<br>socket.on(“String”,function(data)) 监听服务端发送的消息 Sting参数与服务端emit第一个参数相同</p>
<p>监听socket断开与重连。</p>
<p>socket.on(‘disconnect’, function() {<br>    console.log(“与服务其断开”);<br>});</p>
<p>socket.on(‘reconnect’, function() {<br>    console.log(“重新连接到服务器”);<br>});<br>客户端socket.on()监听的事件：<br>connect：连接成功<br>connecting：正在连接<br>disconnect：断开连接<br>connect_failed：连接失败<br>error：错误发生，并且无法被其他事件类型所处理<br>message：同服务器端message事件<br>anything：同服务器端anything事件<br>reconnect_failed：重连失败<br>reconnect：成功重连<br>reconnecting：正在重连<br>当第一次连接时，事件触发顺序为：connecting-&gt;connect；当失去连接时，事件触发顺序为：disconnect-&gt;reconnecting（可能进行多次）-&gt;connecting-&gt;reconnect-&gt;connect。</p>
<h3 id="关于nodejs传输层socket基于net模块"><a href="#关于nodejs传输层socket基于net模块" class="headerlink" title="关于nodejs传输层socket基于net模块"></a>关于nodejs传输层socket基于net模块</h3><p>服务端:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> net = <span class="built_in">require</span>(<span class="string">'net'</span>);</span><br><span class="line"><span class="keyword">var</span> server = net.createServer(<span class="function"><span class="keyword">function</span>(<span class="params">c</span>) </span>&#123; <span class="comment">//'connection' listener</span></span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'server connected'</span>);</span><br><span class="line">  c.on(<span class="string">'end'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'server disconnected'</span>);</span><br><span class="line">  &#125;);</span><br><span class="line">  c.write(<span class="string">'hello\r\n'</span>);</span><br><span class="line">  c.pipe(c);</span><br><span class="line">  &#125;);</span><br><span class="line">  server.listen(端口号, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; <span class="comment">//'listening' listener</span></span><br><span class="line">     <span class="built_in">console</span>.log(<span class="string">'server bound'</span>);</span><br><span class="line">  &#125;);</span><br></pre></td></tr></table></figure>
<p>客户端:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> net = <span class="built_in">require</span>(<span class="string">'net'</span>);                    </span><br><span class="line"><span class="keyword">var</span> client = <span class="keyword">new</span> net.Socket();                         <span class="comment">//前面这2句就不用介绍了</span></span><br><span class="line">client.connect(<span class="number">6000</span>, <span class="string">"127.0.0.1"</span>);                     <span class="comment">//端口号 + 服务器的IP</span></span><br><span class="line"></span><br><span class="line">client.on(<span class="string">'data'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">data</span>) </span>&#123;                    <span class="comment">//接受返回的数据,回调</span></span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'!!!!!!!!:'</span> + data);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">client.on(<span class="string">'error'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">exception</span>) </span>&#123;              <span class="comment">//错误回调</span></span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'socket error:'</span> + exception);</span><br><span class="line"><span class="comment">//    client.end();</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>具体看这篇博客:<a href="http://blog.csdn.net/zhangxin09/article/details/12844975" target="_blank" rel="noopener">http://blog.csdn.net/zhangxin09/article/details/12844975</a></p>
<p>TCO服务端:<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> net = <span class="built_in">require</span>(<span class="string">'net'</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> HOST = <span class="string">'127.0.0.1'</span>;</span><br><span class="line"><span class="keyword">var</span> PORT = <span class="number">6969</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建一个TCP服务器实例，调用listen函数开始监听指定端口</span></span><br><span class="line"><span class="comment">// 传入net.createServer()的回调函数将作为”connection“事件的处理函数</span></span><br><span class="line"><span class="comment">// 在每一个“connection”事件中，该回调函数接收到的socket对象是唯一的</span></span><br><span class="line">net.createServer(<span class="function"><span class="keyword">function</span>(<span class="params">sock</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 我们获得一个连接 - 该连接自动关联一个socket对象</span></span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'CONNECTED: '</span> +</span><br><span class="line">        sock.remoteAddress + <span class="string">':'</span> + sock.remotePort);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 为这个socket实例添加一个"data"事件处理函数</span></span><br><span class="line">    sock.on(<span class="string">'data'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">data</span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'DATA '</span> + sock.remoteAddress + <span class="string">': '</span> + data);</span><br><span class="line">        <span class="comment">// 回发该数据，客户端将收到来自服务端的数据</span></span><br><span class="line">        sock.write(<span class="string">'You said "'</span> + data + <span class="string">'"'</span>);</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 为这个socket实例添加一个"close"事件处理函数</span></span><br><span class="line">    sock.on(<span class="string">'close'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">data</span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'CLOSED: '</span> +</span><br><span class="line">            sock.remoteAddress + <span class="string">' '</span> + sock.remotePort);</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">&#125;).listen(PORT, HOST);</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'Server listening on '</span> + HOST +<span class="string">':'</span>+ PORT);</span><br></pre></td></tr></table></figure></p>
<p>TCO客户端<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> net = <span class="built_in">require</span>(<span class="string">'net'</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> HOST = <span class="string">'127.0.0.1'</span>;</span><br><span class="line"><span class="keyword">var</span> PORT = <span class="number">6969</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> client = <span class="keyword">new</span> net.Socket();</span><br><span class="line">client.connect(PORT, HOST, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'CONNECTED TO: '</span> + HOST + <span class="string">':'</span> + PORT);</span><br><span class="line">    <span class="comment">// 建立连接后立即向服务器发送数据，服务器将收到这些数据 </span></span><br><span class="line">    client.write(<span class="string">'I am Chuck Norris!'</span>);</span><br><span class="line"></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 为客户端添加“data”事件处理函数</span></span><br><span class="line"><span class="comment">// data是服务器发回的数据</span></span><br><span class="line">client.on(<span class="string">'data'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">data</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'DATA: '</span> + data);</span><br><span class="line">    <span class="comment">// 完全关闭连接</span></span><br><span class="line">    client.destroy();</span><br><span class="line"></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 为客户端添加“close”事件处理函数</span></span><br><span class="line">client.on(<span class="string">'close'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'Connection closed'</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></p>
<h3 id="ionic常见问题网站http-ionichina-com-topic-54f051698cbbaa7a56a49f98"><a href="#ionic常见问题网站http-ionichina-com-topic-54f051698cbbaa7a56a49f98" class="headerlink" title="ionic常见问题网站http://ionichina.com/topic/54f051698cbbaa7a56a49f98"></a>ionic常见问题网站<a href="http://ionichina.com/topic/54f051698cbbaa7a56a49f98" target="_blank" rel="noopener">http://ionichina.com/topic/54f051698cbbaa7a56a49f98</a></h3><p><a href="http://www.ionic.ren/" target="_blank" rel="noopener">http://www.ionic.ren/</a><br><a href="http://blog.csdn.net/qq_30100043/article/details/54344881" target="_blank" rel="noopener">http://blog.csdn.net/qq_30100043/article/details/54344881</a><br>ionic设置启动页 <a href="http://www.cnblogs.com/Eplayed/p/5567502.html" target="_blank" rel="noopener">http://www.cnblogs.com/Eplayed/p/5567502.html</a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/开发/" rel="tag"># 开发</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/04/15/first/" rel="next" title="破万卷APP总结三">
                <i class="fa fa-chevron-left"></i> 破万卷APP总结三
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/04/17/second/" rel="prev" title="NodeJs研究">
                NodeJs研究 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_douban"></a>
  <a class="jiathis_button_renren"></a>
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_kaixin001"></a>
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>


          </div>
          

  <p>热评文章</p>
  <div class="ds-top-threads" data-range="weekly" data-num-items="4"></div>


          
  <div class="comments" id="comments">
    
      <div id="hypercomments_widget"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image" src="/uploads/avatar.jpg" alt="腊月的季节">
          <p class="site-author-name" itemprop="name">腊月的季节</p>
          <p class="site-description motion-element" itemprop="description">腊月的季节的个人博客</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">160</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">72</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              我的其他足迹
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://blog.csdn.net/qq_33433029" title="CSDN博客" target="_blank">CSDN博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://github.com/youandme66" title="GitHub" target="_blank">GitHub</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/767025e0c4df/timeline" title="我的简书" target="_blank">我的简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.zhihu.com/people/liu-zhi-hao-85-39/activities" title="我的知乎" target="_blank">我的知乎</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#关于ionic报错"><span class="nav-number">1.</span> <span class="nav-text">关于ionic报错</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关于请求跨域和socket-io跨域"><span class="nav-number">2.</span> <span class="nav-text">关于请求跨域和socket.io跨域</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#socket-io跨域"><span class="nav-number">3.</span> <span class="nav-text">socket.io跨域</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#socket提取session"><span class="nav-number">4.</span> <span class="nav-text">socket提取session</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关于ng-repeat即时更新页面滚动"><span class="nav-number">5.</span> <span class="nav-text">关于ng-repeat即时更新页面滚动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关于socket操作"><span class="nav-number">6.</span> <span class="nav-text">关于socket操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关于nodejs传输层socket基于net模块"><span class="nav-number">7.</span> <span class="nav-text">关于nodejs传输层socket基于net模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ionic常见问题网站http-ionichina-com-topic-54f051698cbbaa7a56a49f98"><span class="nav-number">8.</span> <span class="nav-text">ionic常见问题网站http://ionichina.com/topic/54f051698cbbaa7a56a49f98</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">
  
  &copy;  2016 - 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">腊月的季节</span>
</div>


<div class="powered-by">
   <a class="theme-link" href="http://www.jianshu.com/users/767025e0c4df/timeline">我的简书</a> 
</div>

<div class="theme-info">
  链接 -
  <a class="theme-link" href="https://www.zhihu.com/people/liu-zhi-hao-85-39/activities">
    我的知乎
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>


  



  




	

		<script type="text/javascript">
		_hcwp = window._hcwp || [];

		_hcwp.push({widget:"Bloggerstream", widget_id: 93245, selector:".hc-comment-count", label: "{\%COUNT%\}" });

		
		_hcwp.push({widget:"Stream", widget_id: 93245, xid: "2017/04/16/first/"});
		

		(function() {
		if("HC_LOAD_INIT" in window)return;
		HC_LOAD_INIT = true;
		var lang = (navigator.language || navigator.systemLanguage || navigator.userLanguage || "en").substr(0, 2).toLowerCase();
		var hcc = document.createElement("script"); hcc.type = "text/javascript"; hcc.async = true;
		hcc.src = ("https:" == document.location.protocol ? "https" : "http")+"://w.hypercomments.com/widget/hc/93245/"+lang+"/widget.js";
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(hcc, s.nextSibling);
		})();
		</script>

	





  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("EAvSG3QtXW1dqzq5WQ5CjH7S-gzGzoHsz", "2aiWv7vIfVY4CjKc49aPBHFX");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

</body>
</html>
